package com.movie.ticket.sale.bossassembly.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.movie.ticket.sale.bossassembly.entity.BossAcount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.movie.ticket.sale.bossassembly.entity.Person;
import com.movie.ticket.sale.bossassembly.entity.User;
import com.movie.ticket.sale.bossassembly.pram.CinemaPram;
import com.movie.ticket.sale.bossassembly.pram.ComplainPram;
import com.movie.ticket.sale.bossassembly.pram.OrderMoviePram;
import com.movie.ticket.sale.bossassembly.pram.VipPram;
import com.movie.ticket.sale.pram.MoviePram;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author muzi
 * @since 2020-12-09
 */
public interface BossAcountMapper extends BaseMapper<BossAcount> {
    @Select("select id,name,tel,age,gender,points,illegal,state from t_user")
    IPage<User> findUsers(Page page);
    @Select("select count('user_id') from t_user")
    int findUserNumber();
    @Select("select distinct count('user_id') from t_user_vip where state = 1")
    int findVipNumber();
    @Select("select c.cinema_name ,v.vip_end_data from t_user_vip v left  join t_cinema c on v.cinema_id = c.id where v.state =1")
    IPage<VipPram> findUserVip(Page page);
    @Select("select id ,tel,cinema_name,address,state,service,degree,illegal,lp_id_number,register_number,annual_cost,annual_data,account,tip_root from t_cinema where id  = #{cinemaId}")
    CinemaPram findCinemas(@Param("cinemaId") int cinemaId);
    @Select("select cinema_name,user_id,u.tel,order_movie_id,content,m.state from t_complain m join t_cinema c join t_user u on u.id = m.user_id and c.id = m.cinema_id where m.cinema_id = #{cinemaId}")
    IPage<ComplainPram> findComplain( Page page,@Param("cinemaId") int cinemaId);
    @Select("SELECT o.id ,o.trade_nuo,o.user_id,o.perid_id,c.cinema_name,m.name,o.real_price,o.ticket_price,o.tip,o.number,o.refund,o.change_times,o.discount_id,o.create_time,o.state from t_order_movie o join t_cinema c join t_movie  m on m.id = o.movie_id and o.cinema_id = c.id  where o.user_id = #{userId}")
    IPage<OrderMoviePram> findMovieOrder(Page page,@Param("userId") int userId);
    @Select("SELECT o.id ,o.trade_nuo,o.user_id,o.perid_id,c.cinema_name,m.name,o.real_price,o.ticket_price,o.tip,o.number,o.refund,o.change_times,o.discount_id,o.create_time,d.amount,o.state from t_order_movie o join t_cinema c join t_discount d join t_movie  m on m.id = o. movie_id and o.cinema_id = c.id and o.auditorium_id = d.id where o.cinema_id = #{cinemaId}")
    IPage<OrderMoviePram> findCinemaOrder(Page page,@Param("cinemaId") int cinemaId);
    @Select("select * from t_person where name like CONCAT('%',#{name},'%')")
    IPage<Person> getPersons(Page page,@Param("name")String name);
    @Insert("insert into t_movie (name,type,introduce,time,box_office,movie_grade,state,release_date) values(#{name},#{type},#{introduce},#{time},#{boxOffice},#{movieGrade},#{state},#{releaseDate})" )
    @Options(useGeneratedKeys = true,keyProperty = "id")
    int addMovie(MoviePram moviePram);


}
